package org.example.proxy.dynamic.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class JdkProxy implements InvocationHandler {

    private final Object bean;

    public JdkProxy(Object bean) {
        this.bean = bean;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String methodName = method.getName();
        if ("wakeup".equals(methodName)){
            System.out.println("早安~~~");
        }else if("sleep".equals(methodName)){
            System.out.println("晚安~~~");
        }

        return method.invoke(bean, args);
    }
}
